import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;

public class Test {

    public static void main(String[] args) {
        Stack<Integer> stack=new Stack<>();
        System.out.println(stack.isEmpty());
        System.out.println(stack.empty());
    }

    public static void main5(String[] args) {
        LinkedList<Integer> stack=new LinkedList<>();
        stack.push(10);//头插法入栈
        stack.push(20);
        System.out.println(stack.pop());//头删法出栈
    }


    public boolean IsPopOrder (int[] pushV, int[] popV) {
        Stack<Integer> stack=new Stack<>();
        int j=0;
        for(int i=0;i<pushV.length;i++) {
            stack.push(pushV[i]);
            while(j<popV.length && !stack.empty() && stack.peek()==popV[j]) {
                stack.pop();
                j++;
            }

        }
        return stack.empty();
    }

    public boolean isValid(String s) {
        Stack<Character> stack=new Stack<>();
        for(int i=0;i<s.length();i++) {
            char ch=s.charAt(i);
            //左括号入栈
            if(ch =='{'||ch=='[' ||ch=='(') {
                stack.push(ch);
            }else {
                //遇到右括号,弹出栈顶元素进行匹配
                if(stack.empty()) return false;//栈是空的,直接false
                else {
                    char tmp=stack.peek();//拆箱
                    if(tmp =='{' && ch=='}' || tmp=='[' && ch==']'||tmp=='('&& ch==')') {
                        //当前的括号是匹配的,将其pop出去
                        stack.pop();
                    }else {
                        return false;
                    }
                }
            }
        }
        return stack.empty();
    }

    public int evalRPN(String[] tokens) {
        Stack<Integer> stack=new Stack<>();
        for(int i=0;i<tokens.length;i++){
            String tmp=tokens[i];
            if(isOperation(tmp)) {
                //是运算符
                Integer val2=stack.pop();
                Integer val1=stack.pop();
                switch(tmp) {
                    case "+":
                        stack.push(val1+val2);
                        break;
                    case "-":
                        stack.push(val1-val2);
                        break;
                    case "*":
                        stack.push(val1*val2);
                        break;
                    case "/":
                        stack.push(val1/val2);
                        break;
                }
            }else {
                //不是运算符
                Integer val=Integer.valueOf(tmp);
                stack.push(val);
            }
        }
        return stack.pop();
    }
    //判断是否为符号
    public boolean isOperation(String s) {
        if(s.equals("+") ||s.equals("-")||s.equals("*")||s.equals("/")) {
            return true;
        }
        return false;
    }

    public static void main3(String[] args) {
        MyStack2<String> myStack=new MyStack2<>();
        myStack.push("hello");
        myStack.push("world");
        System.out.println(myStack.peek());
        System.out.println(myStack.pop());
        System.out.println(myStack.peek());
    }
    public static void main2(String[] args) {
        MyStack stack=new MyStack();
        stack.push(10);
        stack.push(20);
        stack.push(30);
        System.out.println(stack.pop());
        System.out.println(stack.peek());
        System.out.println(stack.peek());
    }
    public static void main1(String[] args) {
        Stack<Integer> stack=new Stack<>();
        //入栈
        stack.push(12);
        stack.push(13);
        stack.push(14);
        //出栈(栈顶元素)
        Integer x=stack.pop();//pop的返回值就是它删除掉的栈顶元素
        System.out.println(x);
        //
        Integer y=stack.peek();
        System.out.println(y);
        //虽然stack没有自己的isEmpty方法,但是它继承自Vector,Vector有这个方法
        System.out.println(stack.isEmpty());

    }
}
